<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Login</title>

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="login-body">

<div class="container">
    <br><br><br>
    <form class="form-signin" action="" id="userloginform">
        <div class="form-signin-heading text-center">
            <h1 class="sign-title">账号密码登录</h1>
            <img src="images/login-logo.png"  height="150" width="150"/>
        </div>
        <div class="login-wrap">
            <input type="text" class="form-control" placeholder="账号" autofocus name="u_acount"  id="u_acount">
            <input type="password" class="form-control" placeholder="密码" name="u_password" id="u_password">
            <input type="text" class="form-control" placeholder="验证码" name="u_checkcode" id="u_checkcode">
            <div class="checkcode" style="height: 42px;">
                <img src="getCheckCode" style=" height: 30px;" alt="验证码"  id="checkcode"/>
            </div>
            <button class="btn btn-lg btn-login btn-block" type="button" onclick="userlogin()" id="userlogin">
                <i class="fa fa-check"></i>
            </button>

            <div class="registration">
                <span>
                    <a class=""   onclick="loginTel()">
                        短信验证登录
                    </a>
                </span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span>没有账户?
                    <a class=""   onclick="insertuser()">
                        注册
                    </a>
                </span>
            </div>
            <label class="checkbox">
                <input type="checkbox" value="remember-me"> 记住信息
                <span class="pull-right">
                    <a data-toggle="modal" href="#myModal"> 忘记密码?</a>

                </span>
            </label>

        </div>

        <!-- Modal -->
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">忘记密码?</h4>
                    </div>
                    <div class="modal-body">
                        <p>在下方输入你的电子邮件地址以重设密码。</p>
                        <input type="text" name="email" placeholder="Email" autocomplete="off" class="form-control placeholder-no-fix">

                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                        <button class="btn btn-primary" type="button">提交</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- modal -->

    </form>
    <div style=";text-align: center;color: #8cc657">

    </div>

</div>



<!-- Placed js at the end of the document so the pages load faster -->

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">


    $("#userlogin").click(function(){
        userlogin();
    });

    $(document).keydown(function(){
        if (event.keyCode == 13) {//回车键的键值为13
            userlogin();
        }
    });

    function userlogin(){
        var u_acount = document.getElementById("u_acount").value;
        if(u_acount == null || u_acount==''){
            swal("账号不能为空!", "请输入账号进行登录", "error");
            return false;
        }
        var u_password = document.getElementById("u_password").value;
        if(u_password == null || u_password==''){
            swal("密码不能为空!", "请输入密码进行登录", "error");
            return false;
        }
        var data = $( '#userloginform').serialize();//表单序列化 form表单的id属性值
        $.ajax({
            url : "/user/login_to",//url 统一资源定位符
            type : "POST",
            data : data,
            success : function(result) {

                if(result == 'error'){
                    swal("登录失败!", "账号或密码出现错误", "error");
                }else if(result.search('同学') != -1 ){
                    swal("登录成功!", "请稍后......", "success");
                    window.sessionStorage.setItem("u_name", result);
                    window.location.href = "phoneindex";
                }else if(result.search('老师') != -1 ){
                    swal("登录成功!", "请稍后......", "success");
                    window.sessionStorage.setItem("u_name", result);
                    window.location.href = "teacherindex";
                }else if(result.search('企业') != -1 ){
                    swal("登录成功!", "请稍后......", "success");
                    window.sessionStorage.setItem("u_name", result);
                    window.location.href = "companyindex";
                }else if(result.search('管理员') != -1 ){
                    swal("登录成功!", "请稍后......", "success");
                    window.sessionStorage.setItem("u_name", result);
                    window.location.href = "managerindex";
                }
            },
            error : function(data) {

            }
        });
    }

    function insertuser(){
        window.location.href = "registration";
    }

    function loginTel(){
        window.location.href = "loginTel";
    }

    $(document).ready(function () {
        $('#checkcode').click(function () {
            $.ajax({
                url: 'image/getCheckCode',
                type: 'get',
                success: function (data, status, xhr) {
                    $('#checkcode').attr('src', 'getCheckCode');
                },
            });
        });
    });

</script>

</body>
</html>
